package router

import (
	"ginGms/controller"
	"ginGms/docs"
	"ginGms/middleware"
	"github.com/gin-gonic/gin"
	"github.com/swaggo/files"
	"github.com/swaggo/gin-swagger"
)

func Init() *gin.Engine {
	// 生产环境
	// gin.SetMode(gin.ReleaseMode)
	gin.SetMode(gin.DebugMode)

	r := gin.Default()

	// 跨域
	r.Use(middleware.Cors())

	// 日志
	r.Use(middleware.Loggoer())

	docs.SwaggerInfo.BasePath = "/api/v1"

	v1 := r.Group("/api/v1")
	{
		v1.POST("auth/register", controller.Register)
		v1.POST("auth/login", controller.Login)
		v1.GET("auth/info", middleware.AuthMiddleware(), controller.Info)
	}
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	return r
}
